package org.lboot.ufs.service;

import cn.hutool.core.lang.Validator;
import org.lboot.ufs.entity.UfsFile;
import org.lboot.ufs.params.FileUploadParams;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;

/**
 * @author kindear
 * 统一文件系统控制器
 */
public interface UfsCtl {
//    /**
//     * 文件上传 -> 上传到根目录下 / 指定目录
//     * @param params
//     * @return
//     */
//    public UfsFile upload(FileUploadParams params);
//
//
//
//    /**
//     * 文件上传 / 指定目录
//     * @param params
//     * @param prefix
//     * @return
//     */
//    public UfsFile upload(FileUploadParams params, String prefix);

    /**
     * 文件上传
     * @param params
     * @return
     */
    UfsFile uploadFile(FileUploadParams params);


    /**
     * 文件上传 默认
     * @param file
     * @return
     */
    default UfsFile uploadFile(MultipartFile file){
        FileUploadParams fileUploadParams = new FileUploadParams();
        fileUploadParams.setFile(file);
        return uploadFile(fileUploadParams);
    }

    /**
     * 文件上传 -- 指定前缀
     * @param file
     * @param prefix
     * @return
     */
    default UfsFile uploadFile(MultipartFile file, String prefix){
        FileUploadParams fileUploadParams = new FileUploadParams();
        fileUploadParams.setFile(file);
        fileUploadParams.setPrefix(prefix);
        return uploadFile(fileUploadParams);
    }




    /**
     * 移除文件
     * @param fileId
     * @return
     */
    UfsFile removeFile(String fileId);

    default UfsFile deleteFile(String fileId){
        return removeFile(fileId);
    }


    /**
     * 文件更新
     * @param fileId
     * @param stream
     * @return
     */
    UfsFile updateFile(String fileId, InputStream stream);

    /**
     * 文件更新
     * @param fileId
     * @param file
     * @return
     */
    UfsFile updateFile(String fileId, MultipartFile file);


    default UfsFile putFile(String fileId, InputStream stream){
        return updateFile(fileId, stream);
    }

    default UfsFile putFile(String fileId, MultipartFile file){
        return updateFile(fileId, file);
    }


    /**
     * 获取文件流
     * @param fileId
     * @return
     */
    InputStream getFileStream(String fileId);

    /**
     * 文件下载
     * @param file
     * @return
     */
    public ResponseEntity<byte[]> download(UfsFile file, HttpServletRequest request);


    public ResponseEntity<byte[]> download(String fileId, HttpServletRequest request);

    default ResponseEntity<byte[]> downloadFile(UfsFile file, HttpServletRequest request){
        return download(file,request);
    }
    default ResponseEntity<byte[]> downloadFile(String fileId, HttpServletRequest request){
        return download(fileId,request);
    }

    /**
     * 文件打开
     * @param file
     * @return
     */
    public ResponseEntity<byte[]> open(UfsFile file, HttpServletRequest request);


    public ResponseEntity<byte[]> open(String fileId, HttpServletRequest request);

    default ResponseEntity<byte[]> openFile(UfsFile file, HttpServletRequest request){
        return open(file,request);
    }
    default ResponseEntity<byte[]> openFile(String fileId, HttpServletRequest request){
        return open(fileId,request);
    }


}
